﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DXApplicationTangche.UC.生产计划.生产计划.service;
using DevExpress.XtraGrid.Demos.util;
using DXApplicationTangche.UC.生产计划.编排生产批;
using DXApplicationTangche.UC.生产计划.编排生产批.service;
using DevExpress.XtraGrid.Columns;
using DXApplicationTangche.UC.生产计划.编排生产批.model;

namespace DXApplicationTangche.UC.生产计划.生产计划
{
    public partial class Form未排产订单 : DevExpress.XtraEditors.XtraForm
    {
        private String customerId;
        private List<DTO客户下款式订单> DTO客户下款式订单s = new List<DTO客户下款式订单>();
        private List<DTO客户下款式订单显示> DTO客户下款式订单显示s = new List<DTO客户下款式订单显示>();
        private List<String> orderIds = new List<String>();
        private List<DTO生产批> DTO生产批s = new List<DTO生产批>();
        public Form未排产订单(String customerId)
        {
            InitializeComponent();
            this.customerId = customerId;
            try
            {
                this.DTO客户下款式订单s = 生产计划Service.get客户下款式订单(this.customerId);
                foreach (DTO客户下款式订单 item in this.DTO客户下款式订单s)
                {
                    this.DTO客户下款式订单显示s.Add(new DTO客户下款式订单显示(item));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            this.gridControl客户下款式订单.DataSource = this.DTO客户下款式订单显示s;
            this.gridView客户下款式订单.ActiveFilter.Clear();
            this.gridView客户下款式订单.ActiveFilter.NonColumnFilter = "[status] = 'NOT_SCHEDULED'";
            this.gridView客户下款式订单.ExpandAllGroups();
        }

        private void 开立生产批ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.orderIds = new 生产批Model().buildOrderIds(
                    this.DTO客户下款式订单s,
                    FunctionHelper.GetgridViewValue(
                        this.gridView客户下款式订单,
                        this.gridView客户下款式订单.FocusedRowHandle,
                        "refStyleId"
                        ),
                    FunctionHelper.GetgridViewValue(
                        this.gridView客户下款式订单,
                        this.gridView客户下款式订单.FocusedRowHandle,
                        "status"
                        )
                    );
            try
            {
                //已拆批过的订单查询生产批
                //this.DTO生产批s = 编排生产批Service.get根据订单id查询生产批(this.orderIds);
                if (this.DTO生产批s.Count == 0)
                {
                    //未拆批过的订单初始化生产批
                    //this.DTO生产批s = 编排生产批Service.post初始化生产批(this.orderIds);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            new Form编排生产批(this.DTO生产批s).ShowDialog();
        }

    }
}